package cvc.framework.controller;

import cvc.framework.entity.WebSocketMessage;
import cvc.framework.result.RestMessage;
import cvc.framework.result.RestResult;
import cvc.framework.service.ConnectionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/Connections")
public class ConnectionsController {
    @Autowired
    ConnectionsService connectionsService;

    //获取所有关联关系信息
    @RequestMapping("/getConnections")
    public RestResult getConnections(String targetName, String uuid) {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = connectionsService.getConnections(targetName, uuid);
        return res;
    }

    //通过id获取关联关系信息
    @RequestMapping("/getConnectionById")
    public RestResult getConnectionById(String targetName, String uuid, String id) {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = connectionsService.getConnectionById(targetName, id, uuid);
        return res;
    }

    //添加关联关系信息
    @PostMapping(value = "/addConnection")
    public RestResult addConnection(@RequestBody WebSocketMessage message) {
        System.out.println(message.toString());
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = connectionsService.addConnection(message);
        return res;
    }

    //修改关联关系信息
    @PostMapping(value = "/updateConnection")
    public RestResult updateConnection(@RequestBody WebSocketMessage message) {
        System.out.println(message.toString());
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = connectionsService.updateConnection(message);
        return res;
    }

    //删除关联关系信息
    @RequestMapping("/deleteConnection")
    public RestResult deleteConnection(String targetName, String uuid, String id) {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = connectionsService.deleteConnection(targetName, uuid, id);
        return res;
    }

    //获取脑图
    @RequestMapping("/getRelationalBrainMap")
    public RestResult getRelationalBrainMap(String targetName, String uuid) {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = connectionsService.getRelationalBrainMap(targetName, uuid);
        return res;
    }
}
